package com.jmu.medicineknows.controller;

import com.jmu.medicineknows.dto.DrugPageDto;
import com.jmu.medicineknows.dto.SearchDto;
import com.jmu.medicineknows.entity.Result;
import com.jmu.medicineknows.entity.SaleRecord;
import com.jmu.medicineknows.service.SaleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/count")
public class SaleCountController {
    @Autowired
    SaleService saleService;
    @RequestMapping("/byDrug")
    public Result getTotalByDrug(){
        return saleService.getAll();
    }
    @RequestMapping("/byDate")
    public Result getTotalByDate(){
        return saleService.getAllByDate();
    }
    @PostMapping(value = "/Record2",produces = "application/json;charset=UTF-8")
    public Result getTotalByRecord(@RequestBody DrugPageDto drugPageDto){
        return saleService.getRecords(drugPageDto);
    }
    @RequestMapping("/delete/{id}")
    public Result delete(@PathVariable("id") Integer id){
        return saleService.deleteRecord(id);
    }

    @RequestMapping("/update")
    public Result update(@RequestBody SaleRecord saleRecord){
        System.out.println(saleRecord);
        return saleService.updateRecord(saleRecord);
    }
//    @RequestMapping("/search")
//    public Result search(@RequestBody SearchDto searchDto){
//        System.out.println(searchDto);
//        return saleService.updateRecord(searchDto);
//    }


}
